﻿using System;
using System.Collections.ObjectModel;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Windows.UI.Popups;
using Windows.UI.Xaml;

namespace VivendoByteToolkit.Sample.ViewModel
{
    public class MainViewModel2 : ViewModelBase
    {
        public RelayCommand<int> StartDragCommand { get; set; }
        public RelayCommand<int> DropCommand { get; set; }
        public RelayCommand<int> OverCommand { get; set; }

        string caption;
        public string Caption
        {
            get
            {
                return caption;
            }
            set
            {
                if (value != caption)
                {
                    caption = value;
                    base.RaisePropertyChanged("Caption");
                }
            }
        }

        int selectedItem;
        public int SelectedItem
        {
            get
            {
                return selectedItem;
            }
            set
            {
                if (value != selectedItem)
                {
                    selectedItem = value;
                    base.RaisePropertyChanged("SelectedItem");
                }
            }
        }

        int draggedItem;
        public int DraggedItem
        {
            get
            {
                return draggedItem;
            }
            set
            {
                if (value != draggedItem)
                {
                    draggedItem = value;
                    base.RaisePropertyChanged("DraggedItem");
                }
            }
        }

        public ObservableCollection<int> Items { get; set; }

        public MainViewModel2()
        {
            this.StartDragCommand = new RelayCommand<int>(StartDragCommandExecute);
            this.DropCommand = new RelayCommand<int>(DropCommandExecute);
            this.OverCommand = new RelayCommand<int>(OverCommandExecute, OverCommandCanExecute);

            this.Caption = "Drag'n'drop demo";
            this.Items = new ObservableCollection<int>();
            this.Items.Add(1);
            this.Items.Add(2);
            this.Items.Add(3);
            this.Items.Add(4);
            this.Items.Add(5);
            this.Items.Add(6);
        }

        private void StartDragCommandExecute(int parameter)
        {
            this.Caption = string.Format("You are dragging '{0}'", parameter);
        }

        private void DropCommandExecute(int parameter)
        {
            this.Caption = "Drag'n'drop just finished";
            this.DraggedItem = parameter;
        }

        private void OverCommandExecute(int parameter)
        {
            
        }

        private bool OverCommandCanExecute(int parameter)
        {
            var result = parameter >= 4;

            if (!result)
            {
                this.Caption = "You can't drop this object";
            }

            return result;
        }
    }
}